<?php
class courseController extends appController {
    public function detail($id){
        if(empty($id)){
            return $this->unknownAction();
        }
        
        $data = $this->_model->read($id);
        $this->view->set('item',$data[0]);
        return $this->view();       

    }
public function course($id=null, $name=null, $syllabus=null, $eligibility=null, $descr=null, $benefits=null, $fees=null, $start_date=null, $end_date=null, $video=null){

        if($_SERVER["REQUEST_METHOD"]=='POST'){
            $uploads_dir = 'uploads/';
            $image =$_FILES['image']['name'];
            $image_tmp =$_FILES['image']['tmp_name'];
            move_uploaded_file($image_tmp,"$uploads_dir/$image");
            // $error= array();
            // if ($name=="") {
            //  $error[] ="Course Add !";
            // }
            // if ($syllabus=="") {
            //  $error[] ="Syllabus Add !";
            // }
            // if ($eligibility=="") {
            //  $error[] ="Add eligibility !";
            // }
            // if ($descr=="") {
            //  $error[] ="writen the desc!";
            // }
            // if ($benefits=="") {
            //  $error[] ="Add benefits !";
            // }
            // if ($fees=="") {
            //  $error[] ="fees Add !";
            // }
            // if ($image=="") {
            //  $error[] ="image Add !";
            // }
            // if(!filter_var($video, FILTER_VALIDATE_URL))
            //       {
            //       $error[]="URL is not valid";
            //       }
            // if(!$error){ 
            // // print_r($_POST);exit;
            $id = $this->_model->coursefields($id,$name,$syllabus,$eligibility,$descr,$benefits,$fees,$start_date,$end_date,$image,$video);
            
            if($id !== false){
                header('Location: course');
                exit;
            }
        
        // }
        // else
        // {
        //     $this->view->set('error',$err);  
        // }
        }
            $getcoursefields = $this->_model->getcoursefields();
            $this->view->set('getcoursefields',$getcoursefields[0]);
            $getCourseName = $this->loadModel("interestModel");
            $getCourseName->getInterest([0]);
            print_r($getCourseName->getInterest());
            return $this->view();
    }
}
?> 